<?php
    /**
    * Product Categories get list
    * return in Json format
    * @author trungdt
    * @since Sep 27, 2011
    * 
    * Change logs
    * Oct 2, 2011 - trungdt - Make this action compatible with product edit page
    */
    if (!defined('EXPONENT')) exit('');
    if (exponent_permissions_check(array('administrate','configure'),$loc)){
        //// pagination
        $id = 0;
        $sql_where = '1';
        $search_name = null;
        $obj = null;
        if(isset($_REQUEST['id_cat']))
        {
            $id = intval($_REQUEST['id_cat']);
            $sql_where .= "id_catergory='".$id."'";
            
        }
        if(isset($_REQUEST['search_name']))
        {
            $search_name = $_REQUEST['search_name'];
            $sql_where .= " and name_survey LIKE '%{$search_name}%'"; 
        }
        $page=1;
        if (isset($_REQUEST['page']))
            $page=intval($_REQUEST['page']);
        $pageSize=10;
        if (isset($_REQUEST['pageSize']))
            $pageSize=intval($_REQUEST['pageSize']);
        $start=($page-1)*$pageSize;
        $data=$db->selectObjects('bannermediamodule_item',"{$sql_where} ORDER BY rank ASC limit {$start},{$pageSize}");
        //$data=$db->selectObjects('maillinglist');
        foreach($data as $k=>$v)
        {
            if(($v->item_type==1)||($v->item_type==3))
            {
                $path = $db->selectObject("file","id = {$v->file_id}");
                $path_full = URL_FULL."{$path->directory}/{$path->filename}";   
                $v->file_id =  $path_full;
            }
            else
            {
                $v->file_id = "Not Found";
            }
            if($v->item_type==0) $v->item_type = "Text";
            else if($v->item_type==1) $v->item_type = "Image";
            else if($v->item_type==2) $v->item_type = "Video Embed";
            else $v->item_type = "My video";
        }
        
        $ret_object = null;
        // đưa ra t^ổng s^ố record sẽ trả v^ề
        $ret_object->total = $db->countObjects('bannermediamodule_item',"{$sql_where}");
        $ret_object->rows = $data;
        echo json_encode($ret_object);
    }
    die();
?>


